package com.yao.component.pictureselector.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yao.component.pictureselector.CommonUtil;
import com.yao.component.pictureselector.R;


public class AlertMsgDialog extends Dialog implements View.OnClickListener{
	private String content,confirm;
	private onConfirmListener mOnConfirmListener;
	private int displayWidth;
	private AlertMsgDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public AlertMsgDialog(Context context, String content, String confirm, onConfirmListener onListener) {
		super(context,R.style.AlertDialog);
		this.content=content;
		this.confirm=confirm;
		this.mOnConfirmListener=onListener;
		displayWidth=CommonUtil.getDisplayWidth(context);
		setContentView(initView());
		// TODO Auto-generated constructor stub
	}
	
	private View initView(){
		setCanceledOnTouchOutside(false);

		View view=LayoutInflater.from(getContext()).inflate(R.layout.alert_msg_dialog, null);
		LinearLayout layout=(LinearLayout)view.findViewById(R.id.layout);
		layout.setLayoutParams(new LinearLayout.LayoutParams(displayWidth-100, ViewGroup.LayoutParams.WRAP_CONTENT));
		TextView contentTv=(TextView)view.findViewById(R.id.content);
		Button confirmBtn=(Button)view.findViewById(R.id.confirm);
		contentTv.setText(content);
		confirmBtn.setText(confirm);


		confirmBtn.setOnClickListener(this);
		
		return view;
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
	}
	public interface onConfirmListener{
		void onConfirm();
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		this.dismiss();
		int id=v.getId();
		if (id==R.id.confirm){
			if (mOnConfirmListener!=null) {
				mOnConfirmListener.onConfirm();
			}else {
				this.dismiss();
			}
		}
//		switch (v.getId()) {
//		case R.id.confirm:
//			if (mOnConfirmListener!=null) {
//				mOnConfirmListener.onConfirm();
//			}else {
//				this.dismiss();
//			}
//			break;
//		default:
//			break;
//		}
	}
}
